﻿using System;
using System.Collections.Generic;
using EnetaMvc.Core.Domain.Common;
using EnetaMvc.Core.Domain.Content;

namespace EnetaMvc.Core.Domain.Forums
{
    public class ForumPost : ContentItem
    {
        public virtual User ModifiedBy { get; set; }
        public virtual DateTime Modified { get; set; }
        public virtual string ModificationComment { get; set; }
        public virtual Forum Forum { get; set; }
        public virtual ForumPost Parent { get; set; }
        public virtual int Views { get; set; }

        public virtual IList<ForumPost> Replies { get; set; }

        public ForumPost()
        {
            Replies = new List<ForumPost>();
        }

        public virtual ForumPost GetTopLevelPost()
        {
            var post = this;
            while (post.Parent != null)
                post = post.Parent;

            return post;
        }

        public virtual ForumPost GetLastPost()
        {
            if (Replies.Count == 0)
                return this;

            return Replies[Replies.Count - 1];
        }
    }
}
